﻿    <!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8"><style>.nodata  main {width:1000px;margin: auto;}</style></head><body class="nodata " style=""><div class="main_father clearfix d-flex justify-content-center " style="height:100%;"> <div class="container clearfix " id="mainBox"><main><div class="blog-content-box">
<meta name="referrer" content="no-referrer">
<link rel="stylesheet" type="text/css" href="https://2.lz787.com/assets/1.css">

        <link rel="stylesheet" type="text/css" href="https://csdnimg.cn/release/blogv2/dist/pc/themesSkin/skin-yellow/skin-yellow-28d34ab5fa.min.css"><div class="blog-content-box">
    <div class="article-header-box">
        <div class="article-header">
            <div class="article-title-box">
                <h1 class="title-article" id="articleContentId">python （语音）信号拆分为数据块,计算短期能量和过零率</h1>
            </div>
            <div class="article-info-box">
                <div class="article-bar-top">
                    <img class="article-type-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/original.png" alt="">
                    <div class="bar-content">
                      <a class="follow-nickName " href="https://blog.csdn.net/kirsten111111" target="_blank" rel="noopener" title="the only KIrsTEN">the only KIrsTEN</a>
                    <img class="article-time-img article-heard-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newUpTime2.png" alt="">
                    <span class="time">已于&nbsp;2022-11-03 02:29:19&nbsp;修改</span>
                   <div class="read-count-box">
                      <img class="article-read-img article-heard-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/articleReadEyes2.png" alt="">
                      <span class="read-count">阅读量898</span>
                      <a id="blog_detail_zk_collection" class="un-collection" data-report-click='{"mod":"popu_823","spm":"1001.2101.3001.4232","ab":"new"}'>
                          <img class="article-collect-img article-heard-img un-collect-status isdefault" style="display:inline-block" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarCollect2.png" alt="">
                          <img class="article-collect-img article-heard-img collect-status isactive" style="display:none" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarCollectionActive2.png" alt="">
                          <span class="name">收藏</span>
                          <span class="get-collection">
                              2
                          </span>
                      </a>
                      <div class="read-count-box is-like">
                        <img class="article-read-img article-heard-img" style="display:none" id="is-like-imgactive-new" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newHeart2023Active.png" alt="">
                        <img class="article-read-img article-heard-img" style="display:block" id="is-like-img-new" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newHeart2023Black.png" alt="">
                        <span class="read-count" id="blog-digg-num">点赞数
                            1
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="blog-tags-box">
                    <div class="tags-box artic-tag-box">
                            <span class="label">分类专栏：</span>
                                <a class="tag-link" href="https://blog.csdn.net/kirsten111111/category_12034880.html" target="_blank" rel="noopener">语音和文本处理(Python)</a>
                            <span class="label">文章标签：</span>
                                <a rel="nofollow" data-report-query="spm=1001.2101.3001.4223" data-report-click='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"python","ab":"new","extra":"{\"searchword\":\"python\"}"}' data-report-view='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"python","ab":"new","extra":"{\"searchword\":\"python\"}"}' class="tag-link" href="https://so.csdn.net/so/search/s.do?q=python&amp;t=all&amp;o=vip&amp;s=&amp;l=&amp;f=&amp;viparticle=&amp;from_tracking_code=tag_word&amp;from_code=app_blog_art" target="_blank" rel="noopener">python</a>
                                <a rel="nofollow" data-report-query="spm=1001.2101.3001.4223" data-report-click='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"开发语言","ab":"new","extra":"{\"searchword\":\"开发语言\"}"}' data-report-view='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"开发语言","ab":"new","extra":"{\"searchword\":\"开发语言\"}"}' class="tag-link" href="https://so.csdn.net/so/search/s.do?q=开发语言&amp;t=all&amp;o=vip&amp;s=&amp;l=&amp;f=&amp;viparticle=&amp;from_tracking_code=tag_word&amp;from_code=app_blog_art" target="_blank" rel="noopener">开发语言</a>
                                <a rel="nofollow" data-report-query="spm=1001.2101.3001.4223" data-report-click='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"自然语言处理","ab":"new","extra":"{\"searchword\":\"自然语言处理\"}"}' data-report-view='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"自然语言处理","ab":"new","extra":"{\"searchword\":\"自然语言处理\"}"}' class="tag-link" href="https://so.csdn.net/so/search/s.do?q=自然语言处理&amp;t=all&amp;o=vip&amp;s=&amp;l=&amp;f=&amp;viparticle=&amp;from_tracking_code=tag_word&amp;from_code=app_blog_art" target="_blank" rel="noopener">自然语言处理</a>
                                <a rel="nofollow" data-report-query="spm=1001.2101.3001.4223" data-report-click='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"深度学习","ab":"new","extra":"{\"searchword\":\"深度学习\"}"}' data-report-view='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"深度学习","ab":"new","extra":"{\"searchword\":\"深度学习\"}"}' class="tag-link" href="https://so.csdn.net/so/search/s.do?q=深度学习&amp;t=all&amp;o=vip&amp;s=&amp;l=&amp;f=&amp;viparticle=&amp;from_tracking_code=tag_word&amp;from_code=app_blog_art" target="_blank" rel="noopener">深度学习</a>
                                <a rel="nofollow" data-report-query="spm=1001.2101.3001.4223" data-report-click='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"语音识别","ab":"new","extra":"{\"searchword\":\"语音识别\"}"}' data-report-view='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"语音识别","ab":"new","extra":"{\"searchword\":\"语音识别\"}"}' class="tag-link" href="https://so.csdn.net/so/search/s.do?q=语音识别&amp;t=all&amp;o=vip&amp;s=&amp;l=&amp;f=&amp;viparticle=&amp;from_tracking_code=tag_word&amp;from_code=app_blog_art" target="_blank" rel="noopener">语音识别</a>
                    </div>
                </div>
                <div class="up-time"><span>于&nbsp;2022-11-02 10:00:00&nbsp;首次发布</span></div>
                <div class="slide-content-box">
                    <div class="article-copyright">
                        <div class="creativecommons">
                            版权声明：本文为博主原创文章，遵循<a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="noopener"> CC 4.0 BY-SA </a>版权协议，转载请附上原文出处链接和本声明。
                        </div>
                        <div class="article-source-link">
                            本文链接：<a href="https://blog.csdn.net/kirsten111111/article/details/127380269" target="_blank">https://blog.csdn.net/kirsten111111/article/details/127380269</a>
                        </div>
                    </div>
                </div>
                
                <div class="operating">
                    <a class="href-article-edit slide-toggle">版权</a>
                </div>
            </div>
        </div>

    </div>
    <div id="blogHuaweiyunAdvert"></div>
        <div id="blogColumnPayAdvert">
            <div class="column-group">
                <div class="column-group-item column-group0 column-group-item-one">
                    <div class="item-l">
                        <a class="item-target" href="https://blog.csdn.net/kirsten111111/category_12034880.html" target="_blank" title="语音和文本处理(Python)"
                        data-report-view='{"spm":"1001.2101.3001.6332"}'
                        data-report-click='{"spm":"1001.2101.3001.6332"}'>
                            <img class="item-target" src="https://img-blog.csdnimg.cn/20190918140012416.png?x-oss-process=image/resize,m_fixed,h_224,w_224" alt="">
                            <span class="title item-target">
                                <span>
                                <span class="tit">语音和文本处理(Python)</span>
                                    <span class="dec">专栏收录该内容</span>
                                </span>
                            </span>
                        </a>
                    </div>
                    <div class="item-m">
                        <span>25 篇文章</span>
                        <span>2 订阅</span>
                        <span class="old-add-new-box">
                            <span class="price">yen9.90</span>
                            <span class="oldprice">yen99.00</span>
                        </span>
                    </div>
                    <div class="item-r">
                                    <a class="item-target article-column-subscribe">已订阅
                                    </a>
                                    <a class="item-target column-studyvip-discount column-studyvip-pass"
                                    data-report-view='{"spm":"1001.2015.3001.8590"}'
                                    data-report-click='{"spm":"1001.2015.3001.8590"}'>8折续费
                                    </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="learning_the_member_box">
            <a href="https://www.csdn.net/vip?utm_source=bkzl_cjhy_ckqy" target="_blank">
                <div class="left"><img src="https://csdnimg.cn/release/blogv2/dist/pc/img/iconVIpCrown.png" alt=""><span>您已是超级会员，正在免费阅读会员专享内容</span></div>
                <div class="right"><span>查看更多超级会员权益</span><img src="https://csdnimg.cn/release/blogv2/dist/components/img/vipIconArrowLeftWhite.png" alt=""></div>
            </a>
        </div>
      <div class="ai-abstract-box">
         <div class="ai-abstract">
          <div class="abstract-content">
            <img class="lock-img" src="https://img-home.csdnimg.cn/images/20240711042549.png" alt="">
            这篇博客探讨了如何使用Python将语音信号拆分成数据块，并计算短期能量和过零率以区分浊音和清音。通过块处理和滑动窗口方法，对8000Hz采样率的语音信号进行分析，指出使用较短的帧可能更适合短期静止的语音信号。此外，还介绍了如何计算能量和过零率，并将相关代码封装成函数以供重用。
          </div>
          <span>摘要由CSDN通过智能技术生成</span>
        </div>
      </div>
    <article class="baidu_pl">
        <div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-704d5b9767.css">
             
                <div id="content_views" class="markdown_views prism-atom-one-dark">
                    <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                    </svg>
                    <p>学习目标&#xff08;ILO&#xff09;&#xff1a;<br /> 您应该<br /> 了解如何将&#xff08;语音&#xff09;信号拆分为数据块&#xff08;帧&#xff09;并在这些块上进行分析/转换<br /> 计算短期能量和过零率并将它们可视化以区分浊音和清音语音部分<br /> 了解相关性的基础知识并能够实现相关性估计器<br /> 了解 Python 命令的基本用法:枚举;范围</p> 
<p>正如之前的实验表中所做的那样&#xff0c;我们首先使用 curl 命令从互联网地址 https://staffwww.dcs.shef.ac.uk/people/S.Goetze/sound/speech_8kHz_murder.wav 下载一个波形文件 s[k] 并将其加载到变量 s。 稍后您还需要文件的采样频率&#xff0c;因此将其存储在变量 fs 中。</p> 
<p><strong>任务一&#xff1a;加载并显示语音音频信号</strong><br /> 加载上面的波形文件并在时域中显示信号。</p> 
<pre><code class="prism language-python"><span class="token comment"># Let&#39;s do the ususal necessary and nice-to-have imports</span>
<span class="token operator">%</span>matplotlib inline
<span class="token keyword">import</span> matplotlib<span class="token punctuation">.</span>pyplot <span class="token keyword">as</span> plt  <span class="token comment"># plotting</span>
<span class="token keyword">import</span> seaborn <span class="token keyword">as</span> sns<span class="token punctuation">;</span> sns<span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># styling (uncomment if you want)</span>
<span class="token keyword">import</span> numpy <span class="token keyword">as</span> np               <span class="token comment"># math</span>

<span class="token comment"># download speech and noise example files</span>
s_file_name <span class="token operator">&#61;</span> <span class="token string">&#39;speech_8kHz_murder.wav&#39;</span>
!curl https<span class="token punctuation">:</span><span class="token operator">//</span>staffwww<span class="token punctuation">.</span>dcs<span class="token punctuation">.</span>shef<span class="token punctuation">.</span>ac<span class="token punctuation">.</span>uk<span class="token operator">/</span>people<span class="token operator">/</span>S<span class="token punctuation">.</span>Goetze<span class="token operator">/</span>sound<span class="token operator">/</span><span class="token punctuation">{<!-- --></span>s_file_name<span class="token punctuation">}</span> <span class="token operator">-</span>o <span class="token punctuation">{<!-- --></span>s_file_name<span class="token punctuation">}</span> 

<span class="token keyword">import</span> soundfile <span class="token keyword">as</span> sf
<span class="token keyword">from</span> IPython <span class="token keyword">import</span> display <span class="token keyword">as</span> ipd

<span class="token comment"># load speech wave into variable</span>
s<span class="token punctuation">,</span> fs <span class="token operator">&#61;</span> sf<span class="token punctuation">.</span>read<span class="token punctuation">(</span>s_file_name<span class="token punctuation">)</span>

<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;File &#34;&#39;</span> <span class="token operator">&#43;</span> s_file_name <span class="token operator">&#43;</span> <span class="token string">&#39;&#34; loaded. Its sampling rate is &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>fs<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39; Hz.&#39;</span><span class="token punctuation">)</span>

<span class="token comment"># listen to the sound file (if you want)</span>
ipd<span class="token punctuation">.</span>Audio<span class="token punctuation">(</span>s<span class="token punctuation">,</span> rate<span class="token operator">&#61;</span>fs<span class="token punctuation">)</span>
</code></pre> 
<p><strong>任务 2: 块处理</strong><br /> 为了说明块处理&#xff0c;我们首先切割了 4096 个样本&#xff0c;从音频 10 秒后开始&#xff0c;即从样本号开始。 采样率为 fs&#61;8000Hz 时为 80,000。</p> 
<pre><code class="prism language-python"><span class="token comment"># lets cut out a piece of the data and cisualise it</span>
start_sample <span class="token operator">&#61;</span> <span class="token builtin">int</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token operator">*</span>fs<span class="token punctuation">)</span><span class="token punctuation">;</span>                   <span class="token comment"># start at 10 sec</span>
<span class="token comment">#print(start_sample)</span>
no_of_samples <span class="token operator">&#61;</span> <span class="token number">4096</span><span class="token punctuation">;</span>                        <span class="token comment"># no of samples we want to cut out    </span>
end_sample   <span class="token operator">&#61;</span> start_sample <span class="token operator">&#43;</span> no_of_samples<span class="token punctuation">;</span> <span class="token comment"># last sample to be cut out</span>
sample_vec <span class="token operator">&#61;</span> np<span class="token punctuation">.</span>linspace<span class="token punctuation">(</span>start_sample<span class="token punctuation">,</span> end_sample<span class="token punctuation">,</span> no_of_samples<span class="token punctuation">)</span>
x1<span class="token operator">&#61;</span>s<span class="token punctuation">[</span>start_sample<span class="token punctuation">:</span>end_sample<span class="token punctuation">]</span><span class="token punctuation">;</span>

plt<span class="token punctuation">.</span>figure<span class="token punctuation">(</span>figsize<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>subplot<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>np<span class="token punctuation">.</span>arange<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token builtin">len</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>s<span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>ylabel<span class="token punctuation">(</span><span class="token string">&#39;$x_1[k]$&#39;</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>sample_vec<span class="token punctuation">,</span>x1<span class="token punctuation">,</span><span class="token string">&#39;r&#39;</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>subplot<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>sample_vec<span class="token punctuation">,</span>x1<span class="token punctuation">,</span><span class="token string">&#39;r&#39;</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>xlabel<span class="token punctuation">(</span><span class="token string">&#39;$k$&#39;</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>ylabel<span class="token punctuation">(</span><span class="token string">&#39;$x_1$[&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>start_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;...&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>end_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;]&#39;</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>title<span class="token punctuation">(</span><span class="token string">&#39;$x_1[k]$ for &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>x1<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39; samples between &#39;</span> 
          <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>start_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39; to &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>end_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> 
          <span class="token string">&#39; ($f_s$&#61;&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>fs<span class="token punctuation">)</span> <span class="token operator">&#43;</span><span class="token string">&#39;)&#39;</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>tight_layout<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># this allowes for some space for the title text.</span>
</code></pre> 
<ul><li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" /> I do not understand why end_sample is add not minus?</li><li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" /> what does the x1&#61;s[start_sample:end_sample] mean?</li></ul> 
<p>正如语音处理算法通常所做的那样&#xff0c;遵循块处理&#xff08;滑动窗口方法&#xff09;。</p> 
<pre><code class="prism language-python"><span class="token comment"># lets cut out a piece of the data</span>
Lw   <span class="token operator">&#61;</span> <span class="token number">512</span>                    <span class="token comment"># frame length</span>
Lov  <span class="token operator">&#61;</span> <span class="token number">1</span>                      <span class="token comment"># frame overlap factor </span>
Lhop <span class="token operator">&#61;</span> <span class="token builtin">int</span><span class="token punctuation">(</span>np<span class="token punctuation">.</span><span class="token builtin">round</span><span class="token punctuation">(</span>Lw<span class="token operator">/</span>Lov<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment"># frame hop size</span>

<span class="token comment"># creating grid of axes for subplots</span>
plt<span class="token punctuation">.</span>figure<span class="token punctuation">(</span>figsize<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
ax1 <span class="token operator">&#61;</span> plt<span class="token punctuation">.</span>subplot2grid<span class="token punctuation">(</span>shape<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> loc<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span> colspan<span class="token operator">&#61;</span><span class="token number">5</span><span class="token punctuation">)</span>
ax2 <span class="token operator">&#61;</span> plt<span class="token punctuation">.</span>subplot2grid<span class="token punctuation">(</span>shape<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> loc<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span> colspan<span class="token operator">&#61;</span><span class="token number">1</span><span class="token punctuation">)</span>
ax3 <span class="token operator">&#61;</span> plt<span class="token punctuation">.</span>subplot2grid<span class="token punctuation">(</span>shape<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> loc<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span> colspan<span class="token operator">&#61;</span><span class="token number">1</span><span class="token punctuation">)</span>
ax4 <span class="token operator">&#61;</span> plt<span class="token punctuation">.</span>subplot2grid<span class="token punctuation">(</span>shape<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> loc<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> colspan<span class="token operator">&#61;</span><span class="token number">1</span><span class="token punctuation">)</span>
ax5 <span class="token operator">&#61;</span> plt<span class="token punctuation">.</span>subplot2grid<span class="token punctuation">(</span>shape<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> loc<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> colspan<span class="token operator">&#61;</span><span class="token number">1</span><span class="token punctuation">)</span>
ax6 <span class="token operator">&#61;</span> plt<span class="token punctuation">.</span>subplot2grid<span class="token punctuation">(</span>shape<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> loc<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">,</span> colspan<span class="token operator">&#61;</span><span class="token number">1</span><span class="token punctuation">)</span>
ax_blocks <span class="token operator">&#61;</span> <span class="token punctuation">[</span>ax2<span class="token punctuation">,</span> ax3<span class="token punctuation">,</span> ax4<span class="token punctuation">,</span> ax5<span class="token punctuation">,</span> ax6<span class="token punctuation">]</span>

<span class="token comment"># plot signal part in upper panel (axis ax1)</span>
ax1<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>sample_vec<span class="token punctuation">,</span>x1<span class="token punctuation">,</span><span class="token string">&#39;r&#39;</span><span class="token punctuation">)</span> <span class="token comment">#</span>
ax1<span class="token punctuation">.</span>set_xlabel<span class="token punctuation">(</span><span class="token string">&#39;$k$&#39;</span><span class="token punctuation">)</span>
ax1<span class="token punctuation">.</span>set_ylabel<span class="token punctuation">(</span><span class="token string">&#39;$x_1$[&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>start_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;...&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>end_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;]&#39;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
ax1<span class="token punctuation">.</span>set_title<span class="token punctuation">(</span><span class="token string">&#39;A piece between sample &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>start_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> 
          <span class="token string">&#39; and &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>end_sample<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39; (of length &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>x1<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">&#43;</span> 
          <span class="token string">&#39;) from the 1st channel ($f_s$&#61;&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>fs<span class="token punctuation">)</span> <span class="token operator">&#43;</span><span class="token string">&#39;)&#39;</span><span class="token punctuation">)</span>
          
<span class="token comment"># plot single blocks in lower panels </span>
clrs <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#39;g&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;y&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;m&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;b&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;c&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;k&#39;</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment"># define a vector of colours</span>
<span class="token keyword">for</span> ii<span class="token punctuation">,</span>k <span class="token keyword">in</span> <span class="token builtin">enumerate</span><span class="token punctuation">(</span><span class="token builtin">range</span><span class="token punctuation">(</span>start_sample<span class="token punctuation">,</span>start_sample<span class="token operator">&#43;</span><span class="token number">5</span><span class="token operator">*</span>Lhop<span class="token punctuation">,</span>Lhop<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    block_k_vec <span class="token operator">&#61;</span> np<span class="token punctuation">.</span>arange<span class="token punctuation">(</span>k<span class="token punctuation">,</span>k<span class="token operator">&#43;</span>Lw<span class="token punctuation">)</span>
    block_sig_vec <span class="token operator">&#61;</span> x1<span class="token punctuation">[</span>ii<span class="token operator">*</span>Lhop<span class="token punctuation">:</span>ii<span class="token operator">*</span>Lhop<span class="token operator">&#43;</span>Lw<span class="token punctuation">]</span>
    ax1<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>block_k_vec<span class="token punctuation">,</span>block_sig_vec<span class="token punctuation">,</span>clrs<span class="token punctuation">[</span>ii<span class="token punctuation">]</span><span class="token punctuation">)</span>

    ax_blocks<span class="token punctuation">[</span>ii<span class="token punctuation">]</span><span class="token punctuation">.</span>plot<span class="token punctuation">(</span>block_k_vec<span class="token punctuation">,</span>block_sig_vec<span class="token punctuation">,</span>clrs<span class="token punctuation">[</span>ii<span class="token punctuation">]</span><span class="token punctuation">)</span>
    ax_blocks<span class="token punctuation">[</span>ii<span class="token punctuation">]</span><span class="token punctuation">.</span>set_xlabel<span class="token punctuation">(</span><span class="token string">&#39;$k$&#39;</span><span class="token punctuation">)</span>
    ax_blocks<span class="token punctuation">[</span>ii<span class="token punctuation">]</span><span class="token punctuation">.</span>set_ylim<span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">0.35</span><span class="token punctuation">,</span> <span class="token number">0.35</span><span class="token punctuation">)</span>
    ax_blocks<span class="token punctuation">[</span>ii<span class="token punctuation">]</span><span class="token punctuation">.</span>set_title<span class="token punctuation">(</span><span class="token string">&#39;Block &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>ii<span class="token punctuation">)</span><span class="token punctuation">)</span>

<span class="token comment"># automatically adjust padding horizontally </span>
<span class="token comment"># as well as vertically.</span>
plt<span class="token punctuation">.</span>tight_layout<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>np.round 四舍五入, 可指定精度&#xff0c;但是0.5奇数进偶数不进<br /> colspan是“column span&#xff08;跨列&#xff09;”的缩写。colspan属性用在td标签中&#xff0c;用来指定单元格横向跨越的列数</p> 
<ul><li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" /> np.arange(k,k&#43;Lw) what is the initial value for k</li><li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" /> block_sig_veg?<br /> ax.set_xlim,ax.set_ylim 设置x,y轴的最大值的上限</li></ul> 
<p>上图显示了下面板中长度 LBl&#61;512 的一些框架/块。 给定fs&#61;8000Hz 的采样频率&#xff0c;我们可以计算出一个块的长度是:<br /> LBl&#61;512 样本/8000Hz&#61;64ms<br /> 由于我们知道语音信号在 ≈10…30ms 的时间窗口内&#xff08;短期&#xff09;是静止的&#xff0c;我们可以得出结论&#xff0c;使用较短的帧&#xff08;即较小的 LBl&#xff09;可能是一个好主意。 这也可以在最后两帧&#xff08;蓝色&#xff09;中看到&#xff0c;其中甚至可以从时域信号中观察到统计数据的变化&#xff08;例如&#xff0c;块 3 的前半部分看起来与后半部分有很大不同&#xff09;。</p> 
<p><strong>任务 3:浊音/清音分析</strong><br /> 由于它们具有不同的采样频率fs&#xff0c;我们将它们的采样频率存储在单独的变量fs_e和fs_z中。</p> 
<pre><code class="prism language-python">file_name <span class="token operator">&#61;</span> <span class="token string">&#39;voiced_unvoiced_e.wav&#39;</span>
<span class="token comment">#file_name &#61; &#39;word_fish.wav&#39;         # another one to play around with (if you like)</span>

<span class="token comment"># download speech and noise example files</span>
!curl https<span class="token punctuation">:</span><span class="token operator">//</span>staffwww<span class="token punctuation">.</span>dcs<span class="token punctuation">.</span>shef<span class="token punctuation">.</span>ac<span class="token punctuation">.</span>uk<span class="token operator">/</span>people<span class="token operator">/</span>S<span class="token punctuation">.</span>Goetze<span class="token operator">/</span>sound<span class="token operator">/</span><span class="token punctuation">{<!-- --></span>file_name<span class="token punctuation">}</span> <span class="token operator">-</span>o <span class="token punctuation">{<!-- --></span>file_name<span class="token punctuation">}</span> 
<span class="token comment"># load speech wave into variable</span>
e<span class="token punctuation">,</span> fs_e <span class="token operator">&#61;</span> sf<span class="token punctuation">.</span>read<span class="token punctuation">(</span>file_name<span class="token punctuation">)</span>

<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;File &#34;&#39;</span> <span class="token operator">&#43;</span> file_name <span class="token operator">&#43;</span> <span class="token string">&#39;&#34; loaded. It has a sampling rate of f_s &#61; &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>fs_e<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39; Hz.&#39;</span><span class="token punctuation">)</span>

file_name <span class="token operator">&#61;</span> <span class="token string">&#39;voiced_unvoiced_z.wav&#39;</span>
<span class="token comment">#file_name &#61; &#39;word_speech.wav&#39;     # another one to play around with (if you like)</span>

<span class="token comment"># download speech and noise example files</span>
!curl https<span class="token punctuation">:</span><span class="token operator">//</span>staffwww<span class="token punctuation">.</span>dcs<span class="token punctuation">.</span>shef<span class="token punctuation">.</span>ac<span class="token punctuation">.</span>uk<span class="token operator">/</span>people<span class="token operator">/</span>S<span class="token punctuation">.</span>Goetze<span class="token operator">/</span>sound<span class="token operator">/</span><span class="token punctuation">{<!-- --></span>file_name<span class="token punctuation">}</span> <span class="token operator">-</span>o <span class="token punctuation">{<!-- --></span>file_name<span class="token punctuation">}</span> 
<span class="token comment"># load speech wave into variable</span>
z<span class="token punctuation">,</span> fs_z <span class="token operator">&#61;</span> sf<span class="token punctuation">.</span>read<span class="token punctuation">(</span>file_name<span class="token punctuation">)</span>

<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&#39;File &#34;&#39;</span> <span class="token operator">&#43;</span> file_name <span class="token operator">&#43;</span> <span class="token string">&#39;&#34; loaded. It has a sampling rate of f_s &#61; &#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>fs_z<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39; Hz.&#39;</span><span class="token punctuation">)</span>

<span class="token comment"># listen to the sound file (if you want)</span>
ipd<span class="token punctuation">.</span>Audio<span class="token punctuation">(</span>e<span class="token punctuation">,</span> rate<span class="token operator">&#61;</span>fs_e<span class="token punctuation">)</span>
ipd<span class="token punctuation">.</span>Audio<span class="token punctuation">(</span>z<span class="token punctuation">,</span> rate<span class="token operator">&#61;</span>fs_z<span class="token punctuation">)</span>

</code></pre> 
<p><strong>任务 4: 短期能源与零交叉率(ZCR)</strong><br /> 由于我们将多次重复使用代码&#xff0c;因此我们创建了一个函数。</p> 
<pre><code class="prism language-python"><span class="token keyword">def</span> <span class="token function">calc_STE</span><span class="token punctuation">(</span>signal<span class="token punctuation">,</span> sampsPerFrame<span class="token punctuation">)</span><span class="token punctuation">:</span>
    nFrames       <span class="token operator">&#61;</span> <span class="token builtin">int</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>signal<span class="token punctuation">)</span> <span class="token operator">/</span> sampsPerFrame<span class="token punctuation">)</span>        <span class="token comment"># number of non-overlapping </span>
    E <span class="token operator">&#61;</span> np<span class="token punctuation">.</span>zeros<span class="token punctuation">(</span>nFrames<span class="token punctuation">)</span>
    <span class="token keyword">for</span> frame <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span>nFrames<span class="token punctuation">)</span><span class="token punctuation">:</span>
        startIdx <span class="token operator">&#61;</span> frame <span class="token operator">*</span> sampsPerFrame
        stopIdx <span class="token operator">&#61;</span> startIdx <span class="token operator">&#43;</span> sampsPerFrame
        E<span class="token punctuation">[</span>frame<span class="token punctuation">]</span><span class="token operator">&#61;</span>np<span class="token punctuation">.</span><span class="token builtin">sum</span><span class="token punctuation">(</span>signal<span class="token punctuation">[</span>startIdx<span class="token punctuation">:</span>stopIdx<span class="token punctuation">]</span> <span class="token operator">**</span> <span class="token number">2</span><span class="token punctuation">)</span>
    <span class="token keyword">return</span> E
</code></pre> 
<ul><li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="disabled" /> dose the nFrames &#61; LBI-1?</li></ul> 
<pre><code class="prism language-python">signal <span class="token operator">&#61;</span> e
sampsPerFrame <span class="token operator">&#61;</span> <span class="token builtin">int</span><span class="token punctuation">(</span><span class="token number">0.02</span> <span class="token operator">*</span> fs_e<span class="token punctuation">)</span> <span class="token comment">#20 ms</span>

<span class="token comment"># creating grid for subplots</span>
plt<span class="token punctuation">.</span>figure<span class="token punctuation">(</span>figsize<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>subplot<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>signal<span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>subplot<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>calc_STE<span class="token punctuation">(</span>signal<span class="token punctuation">,</span> sampsPerFrame<span class="token punctuation">)</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>title<span class="token punctuation">(</span><span class="token string">&#39;(Short-term) Energy per block ($L_{\mathrm{Bl}}&#61;&#39;</span> <span class="token operator">&#43;</span> 
          <span class="token builtin">str</span><span class="token punctuation">(</span>sampsPerFrame<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;$, which is &#39;</span> <span class="token operator">&#43;</span> 
          <span class="token builtin">str</span><span class="token punctuation">(</span>sampsPerFrame<span class="token operator">/</span>fs_e<span class="token operator">*</span><span class="token number">1000</span><span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;ms &#64; $f_s&#61;&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>fs_e<span class="token punctuation">)</span> <span class="token operator">&#43;</span><span class="token string">&#39;$)&#39;</span><span class="token punctuation">)</span>
<span class="token comment">#plt.text(18,0.3, &#39;Short Term Energy is higher for voiced speech parts&#39;, style&#61;&#39;italic&#39;,</span>
<span class="token comment">#        bbox&#61;{&#39;facecolor&#39;: &#39;red&#39;, &#39;alpha&#39;: 0.5, &#39;pad&#39;: 10})</span>
plt<span class="token punctuation">.</span>tight_layout<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># automatically adjust padding to make space for titles</span>

ipd<span class="token punctuation">.</span>Audio<span class="token punctuation">(</span>e<span class="token punctuation">,</span> rate<span class="token operator">&#61;</span>fs_e<span class="token punctuation">)</span> <span class="token comment"># add possibility here to listen to the sound once again</span>

signal <span class="token operator">&#61;</span> z
sampsPerFrame <span class="token operator">&#61;</span> <span class="token builtin">int</span><span class="token punctuation">(</span><span class="token number">0.02</span> <span class="token operator">*</span> fs_z<span class="token punctuation">)</span> <span class="token comment">#20 ms</span>

<span class="token comment"># plot</span>
plt<span class="token punctuation">.</span>figure<span class="token punctuation">(</span>figsize<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>subplot<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>signal<span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>subplot<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>plot<span class="token punctuation">(</span>calc_STE<span class="token punctuation">(</span>signal<span class="token punctuation">,</span> sampsPerFrame<span class="token punctuation">)</span><span class="token punctuation">)</span>
plt<span class="token punctuation">.</span>title<span class="token punctuation">(</span><span class="token string">&#39;(Short-term) Energy per block ($L_{\mathrm{Bl}}&#61;&#39;</span> <span class="token operator">&#43;</span> 
          <span class="token builtin">str</span><span class="token punctuation">(</span>sampsPerFrame<span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;$, which is &#39;</span> <span class="token operator">&#43;</span> 
          <span class="token builtin">str</span><span class="token punctuation">(</span>sampsPerFrame<span class="token operator">/</span>fs_z<span class="token operator">*</span><span class="token number">1000</span><span class="token punctuation">)</span> <span class="token operator">&#43;</span> <span class="token string">&#39;ms &#64; $f_s&#61;&#39;</span> <span class="token operator">&#43;</span> <span class="token builtin">str</span><span class="token punctuation">(</span>fs_z<span class="token punctuation">)</span> <span class="token operator">&#43;</span><span class="token string">&#39;$)&#39;</span><span class="token punctuation">)</span>
<span class="token comment">#plt.text(13,0.09, &#39;Short Term Energy is higher for voiced speech parts&#39;, style&#61;&#39;italic&#39;,</span>
<span class="token comment">#        bbox&#61;{&#39;facecolor&#39;: &#39;red&#39;, &#39;alpha&#39;: 0.5, &#39;pad&#39;: 10})</span>
plt<span class="token punctuation">.</span>tight_layout<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># automatically adjust padding to make space for titles</span>

ipd<span class="token punctuation">.</span>Audio<span class="token punctuation">(</span>z<span class="token punctuation">,</span> rate<span class="token operator">&#61;</span>fs_z<span class="token punctuation">)</span> <span class="token comment"># add possibility here to listen to the sound once again</span>
</code></pre> 
<p>上面的信号比我们之前分析的“e”音的浊音要小。我们看到&#xff0c;计算的&#xff08;短期&#xff09;能量低于前一个示例。</p> 
<p>像以前一样&#xff0c;我们将实际计算ZCR的代码放入一个函数中&#xff0c;以便重用。</p> 
<pre><code class="prism language-python"><span class="token keyword">def</span> <span class="token function">calc_ZCR</span><span class="token punctuation">(</span>signal<span class="token punctuation">,</span> sampsPerFrame<span class="token punctuation">)</span><span class="token punctuation">:</span>
    nFrames <span class="token operator">&#61;</span> <span class="token builtin">int</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>signal<span class="token punctuation">)</span> <span class="token operator">/</span> sampsPerFrame<span class="token punctuation">)</span>        <span class="token comment"># number of non-overlapping </span>
    ZCR <span class="token operator">&#61;</span> np<span class="token punctuation">.</span>zeros<span class="token punctuation">(</span>nFrames<span class="token punctuation">)</span>
    <span class="token keyword">for</span> frame <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span>nFrames<span class="token punctuation">)</span><span class="token punctuation">:</span>
        startIdx <span class="token operator">&#61;</span> frame <span class="token operator">*</span> sampsPerFrame
        stopIdx <span class="token operator">&#61;</span> startIdx <span class="token operator">&#43;</span> sampsPerFrame
        signalframe <span class="token operator">&#61;</span> signal<span class="token punctuation">[</span>startIdx<span class="token punctuation">:</span>stopIdx<span class="token punctuation">]</span>
        <span class="token keyword">for</span> k <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token builtin">len</span><span class="token punctuation">(</span>signalframe<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
            ZCR<span class="token punctuation">[</span>frame<span class="token punctuation">]</span> <span class="token operator">&#43;&#61;</span> <span class="token number">0.5</span> <span class="token operator">*</span> <span class="token builtin">abs</span><span class="token punctuation">(</span>np<span class="token punctuation">.</span>sign<span class="token punctuation">(</span>signalframe<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">-</span> np<span class="token punctuation">.</span>sign<span class="token punctuation">(</span>signalframe<span class="token punctuation">[</span>k <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">return</span> ZCR
</code></pre>
                </div>
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-f23dff6052.css" rel="stylesheet">
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-e504d6a974.css" rel="stylesheet">
        </div>
    </article>
  <script>
    $(function() {
      setTimeout(function () {
        var mathcodeList = document.querySelectorAll('.htmledit_views img.mathcode');
        if (mathcodeList.length > 0) {
          for (let i = 0; i < mathcodeList.length; i  ) {
            if (mathcodeList[i].complete) {
              if (mathcodeList[i].naturalWidth === 0 || mathcodeList[i].naturalHeight === 0) {
                var alt = mathcodeList[i].alt;
                alt = '\\('   alt   '\\)';
                var curSpan = $('<span class="img-codecogs"></span>');
                curSpan.text(alt);
                $(mathcodeList[i]).before(curSpan);
                $(mathcodeList[i]).remove();
              }
            } else {
              mathcodeList[i].onerror = function() {
                var alt = mathcodeList[i].alt;
                alt = '\\('   alt   '\\)';
                var curSpan = $('<span class="img-codecogs"></span>');
                curSpan.text(alt);
                $(mathcodeList[i]).before(curSpan);
                $(mathcodeList[i]).remove();
              };
            }
          }
          MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
        }
      }, 500)
    });
  </script>
</div>
<div class="directory-boxshadow-dialog" style="display:none;">
  <div class="directory-boxshadow-dialog-box">
  </div>
   <div class="vip-limited-time-offer-box-new" id="vip-limited-time-offer-box-new">
      <img class="limited-img limited-img-new" src="https://csdnimg.cn/release/blogv2/dist/pc/img/vip-limited-close-newWhite.png">
      <div class="vip-limited-time-top">
        确定要放弃本次机会？
      </div>
      <span class="vip-limited-time-text">福利倒计时</span>
      <div class="limited-time-box-new">
        <span class="time-hour"></span>
        <i>:</i>
        <span class="time-minite"></span>
        <i>:</i>
        <span class="time-second"></span>
      </div>
      <div class="limited-time-vip-box">
        <p>
          <img class="coupon-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/vip-limited-close-roup.png">
          <span class="def">立减 yen</span>
          <span class="active limited-num"></span>
        </p>
        <span class="">普通VIP年卡可用</span>
      </div>
      <a class="limited-time-btn-new" href="https://mall.csdn.net/vip" data-report-click='{"spm":"1001.2101.3001.9621"}' data-report-query='spm=1001.2101.3001.9621'>立即使用</a>
  </div>
</div>    <div class="more-toolbox-new" id="toolBarBox">
      <div class="left-toolbox">
        <div class="toolbox-left">
            <div class="profile-box">
              <a class="profile-href" target="_blank" href="https://blog.csdn.net/kirsten111111"><img class="profile-img" src="https://profile-avatar.csdnimg.cn/2824fe98170346eaa2a31a8dbe79597a_kirsten111111.jpg!1">
                <span class="profile-name">
                  the only KIrsTEN
                </span>
              </a>
            </div>
            <div class="profile-attend">
                <a class="tool-attend tool-bt-button tool-unbt-attend" href="javascript:;" data-report-view='{"mod":"1592215036_002","spm":"1001.2101.3001.4232","extend1":"已关注"}'>已关注</a>
              <a class="tool-item-follow active-animation" style="display:none;">关注</a>
            </div>
        </div>
        <div class="toolbox-middle">
          <ul class="toolbox-list">
            <li class="tool-item tool-item-size tool-active is-like" id="is-like">
              <a class="tool-item-href">
                <img style="display:none;" id="is-like-imgactive-animation-like" class="animation-dom active-animation" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarThumbUpactive.png" alt="">
                <img class="isactive" style="display:none" id="is-like-imgactive" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newHeart2021Active.png" alt="">
                <img class="isdefault" style="display:block" id="is-like-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newHeart2021Black.png" alt="">
                <span id="spanCount" class="count ">
                    1
                </span>
              </a>
              <div class="tool-hover-tip"><span class="text space">点赞</span></div>
            </li>
            <li class="tool-item tool-item-size tool-active is-unlike" id="is-unlike">
              <a class="tool-item-href">
                <img class="isactive" style="margin-right:0px;display:none" id="is-unlike-imgactive" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newUnHeart2021Active.png" alt="">
                <img class="isdefault" style="margin-right:0px;display:block" id="is-unlike-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newUnHeart2021Black.png" alt="">
                <span id="unlikeCount" class="count "></span>
              </a>
              <div class="tool-hover-tip"><span class="text space">踩</span></div>
            </li>
            <li class="tool-item tool-item-size tool-active is-collection ">
              <a class="tool-item-href" href="javascript:;" data-report-click='{"mod":"popu_824","spm":"1001.2101.3001.4130","ab":"new"}'>
                <img style="display:none" id="is-collection-img-collection" class="animation-dom active-animation" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarCollectionActive.png" alt="">
                <img class="isdefault" id="is-collection-img" style="display:block" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCollectBlack.png" alt="">
                <img class="isactive" id="is-collection-imgactive" style="display:none" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCollectActive.png" alt="">
                <span class="count get-collection " data-num="2" id="get-collection">
                    2
                </span>
              </a>
              <div class="tool-hover-tip collect">
                <div class="collect-operate-box">
                  <span class="collect-text" id="is-collection">
                    收藏
                  </span>
                </div>
              </div>
              <div class="tool-active-list">
                <div class="text">
                  觉得还不错?
                  <span class="collect-text" id="tool-active-list-collection">
                    一键收藏
                  </span>
                 <img id="tool-active-list-close" src="https://csdnimg.cn/release/blogv2/dist/pc/img/collectionCloseWhite.png" alt="">
                </div>
              </div>
            </li>
          <li class="tool-item tool-item-size tool-active tool-item-comment">
            <div class="guide-rr-first">
              <img src="https://csdnimg.cn/release/blogv2/dist/pc/img/guideRedReward01.png" alt="">
              <button class="btn-guide-known">知道了</button>
            </div>
              <a class="tool-item-href go-side-comment" data-report-click='{"spm":"1001.2101.3001.7009"}'>
              <img class="isdefault" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newComment2021Black.png" alt="">
              <span class="count">
                    0
              </span>
            </a>
            <div class="tool-hover-tip"><span class="text space">评论</span></div>
          </li>
          <li class="tool-item tool-item-bar">
          </li>
          <li class="tool-item tool-item-size tool-active tool-QRcode" data-type="article" id="tool-share">
            <a class="tool-item-href" href="javascript:;" data-report-view='{"spm":"3001.4129","extra":{"type":"blogdetail"}}'>
              <img class="isdefault" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newShareBlack.png" alt="">
            </a>
              <div class="QRcode" id="tool-QRcode">
              <div class="share-bg-box">
                <div class="share-content">
                  <a id="copyPosterUrl" data-type="link" class="btn-share">复制链接</a>
                </div>
                <div class="share-content">
                  <a class="btn-share" data-type="qq">分享到 QQ</a>
                </div>
                <div class="share-content">
                  <a class="btn-share" data-type="weibo">分享到新浪微博</a>
                </div>
                <div class="share-code">
                  <div class="share-code-box" id='shareCode'></div>
                  <div class="share-code-text">
                    <img src="https://csdnimg.cn/release/blogv2/dist/pc/img/share/icon-wechat.png" alt="">扫一扫
                  </div>
                </div>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="toolbox-right"><script type="text/javascript" crossorigin src="https://g.csdnimg.cn/common/csdn-login-box/csdn-login-box.js"></script></html>